

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:huajianshe_app/base/AppNavigator.dart';
import 'package:huajianshe_app/common/AppRouter.dart';
import 'package:huajianshe_app/common/C.dart';
import 'package:huajianshe_app/common/TS.dart';
import 'package:huajianshe_app/common/load_image.dart';
import 'package:huajianshe_app/common/space.dart';
import 'package:huajianshe_app/utils/dialog_util.dart';
import 'package:huajianshe_app/widget/SmartButton.dart';

import 'LeaveMessageDialog.dart';
import 'model/UserModel.dart';

class UserInfoAppBar extends StatelessWidget {

  final UserInfo? userInfo;
  final int? circleId;

  const UserInfoAppBar({Key? key, this.userInfo, this.circleId}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return
      Container(height: 48, child:
        Row(mainAxisSize: MainAxisSize.max, crossAxisAlignment: CrossAxisAlignment.center, children: [
          W(15),
          GestureDetector(onTap: () { AppNavigator.pop(context); }, child: LoadImage('ic_black_arrow')),
          W(15),
          Column(mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.start, children: [
            Row(mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.start, children: [
              Text('${userInfo?.nickname}', style: TS(12, C.gray333),),
              W(3.5),
              LoadImage('ic_female')
            ]),
            Text('${userInfo?.companyName}${userInfo?.positionName}', style: TS(11, C.gray666),)
          ]),
          Spacer(),
          SmartButton(text: userInfo?.isFriend == 1 ? '聊天' : '留言', fontSize: 11, textColor: Colors.white, width: 57, height: 24, borderWidth: 1,
            drawableLeft: LoadImage('ic_message'), drawablePadding: 3, radius: 24, onPressed: () { chatOrMessage(context); }),
          W(9)
        ]),
        decoration: BoxDecoration(
          boxShadow: [BoxShadow(offset: Offset(0, -2.5), color: Color.fromRGBO(0, 0, 0, 0.07), blurRadius: 14)]
        ),
      );
  }

  void chatOrMessage(BuildContext context) {
    if (userInfo?.isFriend == 1) { // 好友去聊天
      AppNavigator.push(context, RouteName.CHAT);
    } else { // 非好友去留言
      if (circleId != null) {
        DialogUtil.showBottomDialogV2(context, LeaveMessageDialog(circleId!), height: 0.8, radius: 13,
            bgColor: Colors.transparent, margin: EdgeInsets.symmetric(horizontal: 5));
      }
    }
  }

}